export default {
  data () {
    return {
      asideMenus: [],
      showSubmenu: -1
    }
  },
  created () {
    this.loadAsideMenus()
  },
  methods: {
    // 退出登录
    async logout () {
      try {
        let res = await this.$confirm(
          '此操作将退出用户登录, 是否继续?',
          '提示',
          {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }
        )

        console.dir(res)
        // 点击确定后删除token
        localStorage.removeItem('token')
        this.$router.replace('/login')

        this.$message({
          type: 'success',
          message: '退出成功!'
        })
      } catch (error) {
        this.$message({
          type: 'info',
          message: '已取消退出'
        })
      }
    },
    // 侧边栏导航选项卡打开的回调函数
    handleOpen (key, keyPath) {
      console.log(key, keyPath)
    },
    handleClose (key, keyPath) {
      console.log(key, keyPath)
    },
    // 从服务器获取侧边栏菜单
    async loadAsideMenus () {
      let res = await this.$axios.get(`menus`)
      console.log(res)
      this.asideMenus = res.data.data
    }
  }
}
